﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DBProvider.Providers
{
	public class AreaProvider : IAreaProvider
	{

		#region IAreaProvider Members

		public List<StateProvince> GetAllStateProvince()
		{
			List<StateProvince> result = null;

			try
			{
				using (DBHealthCommunityDataContext db = new DBHealthCommunityDataContext())
				{
					result = db.StateProvinces.ToList();
				}
			}
			catch (Exception exc)
			{
				throw exc;
			}

			return result;
		}

		public List<City> GetCityByStateProvince(int stateProvinceID)
		{
			if (stateProvinceID <= 0)
			{
				throw new ArgumentOutOfRangeException();
			}

			List<City> result = null;

			try
			{
				using (DBHealthCommunityDataContext db = new DBHealthCommunityDataContext())
				{
					var data = db.Cities.Where(c => c.StateProvinceID == stateProvinceID);

					if (data != null)
					{
						result = data.ToList();
					}
				}
			}
			catch (Exception exc)
			{
				throw exc;
			}

			return result;
		}

		#endregion
	}
}
